<template>
	<view class="container">
		<u--form>
			<u-form-item label="Port口" prop="switchOne" labelWidth="140rpx">
				<uni-data-select
					:clear="false"
					v-model="query.port"
					:localdata="portList"
					placeholder="请选择模式"
				></uni-data-select>
			</u-form-item>
		</u--form>
		<u-toast ref="uToast"></u-toast>
		<view class="commonButton">
			<u-button type="primary" :disabled="!query.port" @click="confirmCar">确认台车到位</u-button>
		</view>
	</view>
</template>

<script>
	import { getOutPortAPI, supplayCarAPI } from '@/api/work/outbound'
	import uniDataSelect from '../../../node_modules/@dcloudio/uni-ui/lib/uni-data-select/uni-data-select.vue'
	export default {
		components: {
			uniDataSelect
		},
		data() {
			return {
				query: {
					port: ''
				},
				portList: []
			};
		},
		mounted() {
			this.getOutPort()
		},
		methods: {
			async getOutPort() {
				const res = await getOutPortAPI()
				console.log(res)
				this.portList = res.data.map(item => {
					return {
						text: item.name,
						value: item.code
					}
				})
			},
			async confirmCar() {
				const submitForm = {
					portCode: this.query.port
				}
				const res = await supplayCarAPI(submitForm)
				if (res.code === 200) {
					this.query.port = ''
					this.$refs.uToast.show({
						type: 'success',
						message: res.message
					})
				} else {
					return this.$refs.uToast.show({
						type: 'warning',
						message: res.message
					})
				}
			}
		}
	}
</script>

<style lang="scss">

</style>
